import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";

Vue.use(VueRouter);

const router = new VueRouter({
  routes: [
    {
      path: "/",
      name: "home",
      redirect: "/films",
      component: HomeView,
      children: [
        {
          path: "films",
          name: "films",
          redirect: "/films/hot",
          component: () => import("@/views/HomeFilmsView.vue"),
          children: [
            {
              path: "hot",
              name: "hot",
              component: () => import("@/views/FilmHotView.vue"),
              meta: {
                title: "热映",
              },
            },
            {
              path: "wait",
              name: "wait",
              component: () => import("@/views/FilmWaitView.vue"),
              meta: {
                title: "待映",
              },
            },
            {
              path: "classic",
              name: "classic",
              component: () => import("@/views/FilmClassicView.vue"),
              meta: {
                title: "经典电影",
              },
            },
          ],
        },
        {
          path: "cinemas",
          name: "cinemas",
          component: () => import("@/views/HomeCinemasView.vue"),
          meta: {
            title: "影院",
          },
        },
        {
          path: "video",
          name: "video",
          component: () => import("@/views/HomeVideoView.vue"),
          meta: {
            title: "视频",
          },
        },
        {
          path: "center",
          name: "center",
          component: () => import("@/views/HomeCenterView.vue"),
          meta: {
            title: "个人中心",
          },
        },
      ],
    },
    {
      path: "/login",
      name: "login",
      component: () => import("@/views/LoginView.vue"),
      meta: {
        title: "登录",
      },
    },
    {
      path: "/register",
      name: "register",
      component: () => import("@/views/RegisterView.vue"),
      meta: {
        title: "注册",
      },
    },
    {
      path: "/film",
      name: "film",
      component: () => import("@/views/FilmDetailView.vue"),
      meta: {
        title: "电影详情",
      },
    },
    {
      path: "/cinemas/movie",
      name: "cinemasmovie",
      component: () => import("@/views/CinemasMovieView.vue"),
      meta: {
        title: "影院-电影",
      },
    },
    {
      path: "/move",
      name: "move",
      component: () => import("@/views/MoveView.vue"),
      meta: {
        title: "购票",
      },
    },
    {
      path: "/select",
      name: "select",
      component: () => import("@/views/SelectView.vue"),
      meta: {
        title: "选座",
      },
    },
  ],
});

router.beforeEach((to, from, next) => {
  // 设置页面的 title
  const title = to.meta.title;
  document.title = title;
  next();
});

export default router;
